import java.util.LinkedList;

class Solution {
    class ListNode {
        int val;
      ListNode next;
        public ListNode(int val) {
            this.val = val;
        }
    }
        public int[] reversePrint(ListNode head) {
            LinkedList<Integer> list=new LinkedList<>();
            ListNode cur=head;
            while(cur!=null){
                list.addFirst(cur.val);
                cur=cur.next;
            }
            int [] arr=new int[list.size()];
            for(int i=0;i<list.size();i++){
                arr[i]=list.poll();
            }
            return arr;
        }
    public boolean findNumberIn2DArray(int[][] matrix, int target) {
        for(int i=0;i<matrix.length;i++){
            for(int j=matrix[0].length-1;j>=0;j--){
                if(matrix[i][j]<target){
                    i++;
                }else if (matrix[i][j]>target){
                    j--;
                }else{
                    return true;
                }
            }
        }
      return false;
    }
}